﻿using strange.extensions.context.api;
using strange.extensions.dispatcher.eventdispatcher.api;
using strange.extensions.mediation.impl;
using System;
using System.Collections.Generic;


namespace CommonIoC
{
    public class HelperMsgPanelMediator : Mediator
    {

       

        [Inject]
        public HelperMsgPanelView view { get; set; }
        [Inject(ContextKeys.CONTEXT_DISPATCHER)]//全局的dispatcher
        public IEventDispatcher dispatcher { get; set; }

        public override void OnRegister()
        {

            // dispatcher.AddListener(PlayerGameState.IsDoingTalk, onIsDoingTalk);
            //  dispatcher.AddListener(PlayerGameState.CanMove_And_CanTouchWSAD, onCanMove_And_CanTouchWSAD);
            dispatcher.AddListener(TopButtonListEvent.ClickHelper, onShowHelperPanel );


            dispatcher.AddListener(TopButtonListEvent.ClickBack, onTopButtonListClickBack);

            AddBackButtonClickFunc();
        }

        private void onShowHelperPanel(IEvent payload)
        {
            view.ShowThisUI();
        }

        private void onTopButtonListClickBack(IEvent payload)
        {
            view.CloseThisUI();
        }


        void AddBackButtonClickFunc()
        {
            if (view.btn_back != null)
            {
                view.btn_back.onClick.AddListener(delegate ()
                {

                    dispatcher.Dispatch( HelperMsgPanelEvent.ClickBack);
                    view.CloseThisUI();
                });
            }
        }


        public override void OnRemove()
        {
            //dispatcher.RemoveListener(PlayerStageCommandEvent.canMove, onPlayerStageChangeTocanMove);
            //dispatcher.RemoveListener(PlayerStageCommandEvent.doTalk, onPlayerStageChangeTodoTalk);

            //view.dispatcher.RemoveListener(GameEvent.InputKey, onInputKey);
        }


    }
}
